package com.zhibang.ydgl.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhibang.comnom.vo.DrugstoreVo;
import com.zhibang.ydgl.service.DrugStoreService;
import com.zhibang.comnom.re.Result;
import com.zhibang.comnom.re.ResultCode;
import com.zhibang.comnom.domain.Syd;
import com.zhibang.comnom.domain.Sydfd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/store")
@Api(tags = "门店列表",value = "查看药店")
public class DrugStoreController {

    @Resource
    private DrugStoreService drugStoreService;

    @ApiOperation(value = "查看药店门店",notes = "查看总店信息",httpMethod = "GET")
    @RequestMapping(value = "mend",method = RequestMethod.GET)
    public Result menStore(String searchParams) throws Exception{
        ObjectMapper objectMapper = new ObjectMapper();
        DrugstoreVo drugstoreVo = null;
        if (searchParams!=null){
            drugstoreVo=objectMapper.readValue(searchParams, DrugstoreVo.class);
            System.out.println(drugstoreVo);
        }
        List<Syd> sccDrugstores = drugStoreService.queryStores(drugstoreVo);

        return Result.ok(ResultCode.SUCCESS,sccDrugstores);
    }


    @ApiOperation(value = "查看药点分店",notes = "查看药点分店",httpMethod = "GET")
    @RequestMapping(value = "fend",method = RequestMethod.GET)
    public Result fenStore(String searchParams) throws Exception{
        ObjectMapper objectMapper = new ObjectMapper();
        DrugstoreVo drugstoreVo = null;
        if (searchParams!=null && "".equals(searchParams)){
            drugstoreVo=objectMapper.readValue(searchParams, DrugstoreVo.class);
            System.out.println(drugstoreVo);
        }
        List<Sydfd> sydfds = drugStoreService.queryFd(drugstoreVo);
        return Result.ok(ResultCode.SUCCESS,sydfds);
    }

}
